package diedai;

//牛顿迭代法解 x = cos x；
public class XEqualCosX {

	public static void main(String[] args) {
		double Xn= 0.75;  //初始值
		int i=0;
		while( Math.abs( fun(Xn) ) >0.000001 ){
			Xn = Xn - fun(Xn) / fun1(Xn);  //迭代的公式
			System.out.println("第" +( ++i )+ "次迭代，结果为：" + Xn);
		}
	}
	//原函数
	public static double fun(double x){
		//System.out.println(x - Math.cos(x));
		return x - Math.cos(x);
	}
	//导函数
	public static double fun1(double x){
		return 1 + Math.sin(x);
	}
}
